package com.czy.util.json;

import com.czy.convert.Converter;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.sql.Timestamp;
import java.time.LocalDateTime;

/**
 * @author chenzy
 * @since 2022-05-10
 **/
public class SerializerTimestamp2LocalDateTime extends JsonSerializer<Timestamp> implements Converter<Timestamp, LocalDateTime> {
    @Override
    public void serialize(Timestamp value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeObject(convert(value));
    }


    @Override
    public LocalDateTime convert(Timestamp source) {
        return source.toLocalDateTime();
    }
}
